 
package com.zkmonitor.interceptor;

import com.zkmonitor.common.UserHolder;
import com.zkmonitor.model.Cluster;
import com.zkmonitor.model.User;
import com.zkmonitor.util.ClusterUtil;
import com.zkmonitor.util.AuthStrategy;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class NavInterceptor extends HandlerInterceptorAdapter {

    @Autowired
    UserHolder userHolder;

    @Autowired
    private AuthStrategy authStrategy;

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView)
            throws Exception {
        List<Cluster> clusters = ClusterUtil.getClusters();
        User user = userHolder.getUser();
        modelAndView.addObject("clusters", clusters);
        modelAndView.addObject("user", user);
        modelAndView.addObject("isAdmin", authStrategy.isAdmin());

        super.postHandle(request, response, handler, modelAndView);
    }
}
